package com.dt.platform.generator.module.oa;

import com.dt.platform.constants.db.OaTables;
import com.dt.platform.constants.enums.oa.ProjectStatusEnum;
import com.dt.platform.domain.oa.Project;
import com.dt.platform.domain.oa.ProjectTask;
import com.dt.platform.domain.oa.meta.ProjectMeta;
import com.dt.platform.domain.oa.meta.ProjectTaskMeta;
import com.dt.platform.domain.oa.meta.SealApplyMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.oa.page.ProjectTaskPageController;
import com.dt.platform.proxy.oa.ProjectTaskServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.domain.system.DictItem;
import org.github.foxnic.web.domain.system.meta.DictItemMeta;
import org.github.foxnic.web.proxy.system.DictItemServiceProxy;

public class AProjectTaskGtr extends BaseCodeGenerator {


    public AProjectTaskGtr() {
        super(OaTables.OA_PROJECT_TASK.$TABLE,"705020984087805957");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(OaTables.OA_PROJECT_TASK.ID).basic().hidden(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.CT).search().fuzzySearch();

        cfg.getPoClassFile().addSimpleProperty(DictItem.class,"workTypeDict","workTypeDict","workTypeDict");

        cfg.getPoClassFile().addSimpleProperty(DictItem.class,"priorityDict","priorityDict","priorityDict");

        cfg.getPoClassFile().addSimpleProperty(Employee.class,"leader","leader","leader");


        cfg.getPoClassFile().addListProperty(Employee.class,"partUserList","partUserList","partUserList");
        cfg.getPoClassFile().addListProperty(String.class,"partUserStrList","partUserStrList","partUserStrList");

        cfg.getPoClassFile().addSimpleProperty(Project.class,"project","project","project");
        cfg.getPoClassFile().addSimpleProperty(String.class,"selectRange","selectRange","selectRange");


        cfg.getPoClassFile().addSimpleProperty(String.class,"taskRcdCount","taskRcdCount","taskRcdCount");
        cfg.getPoClassFile().addSimpleProperty(String.class,"taskRcdMineCount","taskRcdMineCount","taskRcdMineCount");
        cfg.getPoClassFile().addSimpleProperty(String.class,"workTimeTotal","workTimeTotal","workTimeTotal");

        cfg.getPoClassFile().addSimpleProperty(String.class,"tabStatus","tabStatus","tabStatus");

        cfg.view().field(ProjectTaskMeta.WORK_TIME_TOTAL).basic().label("实际工时");
        cfg.view().field(ProjectTaskMeta.TASK_RCD_COUNT).basic().label("工作记录总数");
        cfg.view().field(ProjectTaskMeta.TASK_RCD_MINE_COUNT).basic().label("我的工作记录数");

        cfg.view().field(ProjectTaskMeta.TASK_RCD_MINE_COUNT).table().disable(true);
        cfg.view().field(ProjectTaskMeta.TASK_RCD_COUNT).table().disable(true);
        cfg.view().field(ProjectTaskMeta.ACTUAL_W_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.ESTIMATE_E_TIME).form().dateInput().defaultNow().format("yyyy-MM-dd").type(DatePickerType.date).search().range();
        cfg.view().field(OaTables.OA_PROJECT_TASK.ACTUAL_E_TIME).form().dateInput().format("yyyy-MM-dd").type(DatePickerType.date).search().range();
        cfg.view().field(OaTables.OA_PROJECT_TASK.FINISH_PCT).form().numberInput().scale(2).decimal().defaultValue(0.0);
        cfg.view().field(OaTables.OA_PROJECT_TASK.ESTIMATE_W_TIME).form().numberInput().scale(2).decimal().defaultValue(1.0);
        cfg.view().field(OaTables.OA_PROJECT_TASK.LEADER_ID).table().fillBy("leader","name");
        cfg.view().field(OaTables.OA_PROJECT_TASK.LEADER_ID).form()
                .button().chooseEmployee(true);


        cfg.view().field(ProjectTaskMeta.TAB_STATUS).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_TASK.CODE).search().fuzzySearch();

        cfg.view().search().inputLayout(
                new Object[]{
                        OaTables.OA_PROJECT_TASK.TASK_STATUS,
                        OaTables.OA_PROJECT_TASK.WORK_TYPE,
                        OaTables.OA_PROJECT_TASK.PRIORITY,
                        OaTables.OA_PROJECT_TASK.CODE,
                }
        );
        cfg.view().list().disableBatchDelete();
        cfg.view().field(OaTables.OA_PROJECT_TASK.TASK_STATUS).form().validate().required().form().selectBox().enumType(ProjectStatusEnum.class).defaultIndex(0);

        cfg.view().field(OaTables.OA_PROJECT_TASK.WORK_TYPE)
                .form().validate().required().form().selectBox().queryApi(DictItemServiceProxy.QUERY_PAGED_LIST+"?dictCode=oa_project_work_type")
                .defaultIndex(0).paging(true).filter(true).toolbar(true)
                .valueField(DictItemMeta.CODE).
                textField(DictItemMeta.LABEL).
                fillWith(ProjectTaskMeta.WORK_TYPE_DICT).muliti(false);

        cfg.view().field(OaTables.OA_PROJECT_TASK.PRIORITY)
                .form().validate().required().form().selectBox().queryApi(DictItemServiceProxy.QUERY_PAGED_LIST+"?dictCode=oa_project_task_priority")
                .defaultIndex(0).paging(true).filter(true).toolbar(true)
                .valueField(DictItemMeta.CODE).
                textField(DictItemMeta.LABEL).
                fillWith(ProjectTaskMeta.PRIORITY_DICT).muliti(false);



        cfg.view().field(OaTables.OA_PROJECT_TASK.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.CREATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.CREATE_TIME).table().disable(true);
        
        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);


        cfg.view().field(OaTables.OA_PROJECT_TASK.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.UPDATE_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.CREATE_BY).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_TASK.FILE_ID).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.PRIORITY).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_TASK.STATUS).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_TASK.CT).table().disable(true);

        cfg.view().field(ProjectTaskMeta.PART_USER_LIST).table().disable(true);



        cfg.view().list().columnLayout(OaTables.OA_PROJECT_TASK.PROJECT_ID,OaTables.OA_PROJECT_TASK.CODE,
                OaTables.OA_PROJECT_TASK.TASK_STATUS,
                OaTables.OA_PROJECT_TASK.NAME,
                OaTables.OA_PROJECT_TASK.LEADER_ID,
                OaTables.OA_PROJECT_TASK.FINISH_PCT,
                OaTables.OA_PROJECT_TASK.ESTIMATE_W_TIME,
                ProjectTaskMeta.WORK_TIME_TOTAL,
                ProjectTaskMeta.PART_USER_STR_LIST
               );

        cfg.view().field(OaTables.OA_PROJECT_TASK.NAME).form().validate().required();
        cfg.view().field(OaTables.OA_PROJECT_TASK.CT).form().validate().required().form().textArea().height(120);
        cfg.view().field(OaTables.OA_PROJECT_TASK.FILE_ID).form().upload().maxFileCount(6);

        cfg.view().field(ProjectTaskMeta.PART_USER_STR_LIST).basic().label("协作人员").form()
                .button().chooseEmployee(false);


        cfg.view().formWindow().bottomSpace(50);
        cfg.view().formWindow().width(Config.baseFormWidth);
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT_TASK.NAME
                },
                new Object[] {
                        OaTables.OA_PROJECT_TASK.TASK_STATUS
                },
                new Object[] {
                        OaTables.OA_PROJECT_TASK.PRIORITY
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT_TASK.WORK_TYPE,
                        OaTables.OA_PROJECT_TASK.FINISH_PCT
                },
                new Object[] {
                        OaTables.OA_PROJECT_TASK.ESTIMATE_E_TIME,
                        OaTables.OA_PROJECT_TASK.ACTUAL_E_TIME
                },
                new Object[] {
                        OaTables.OA_PROJECT_TASK.ESTIMATE_W_TIME
                }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT_TASK.LEADER_ID,

                },
                new Object[] {
                        ProjectTaskMeta.PART_USER_STR_LIST
                }
        );

        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT_TASK.CT,
                        OaTables.OA_PROJECT_TASK.FILE_ID
                }
        );

      //  cfg.view().list().operationColumn().addActionButton("工作","work","action-work");
        cfg.view().list().operationColumn().addActionButton("工作清单","workList","action-work-list");
        cfg.view().list().addJsVariable("DATA_RANGE","[[${dataRange}]]","dataRange");
        cfg.view().list().addJsVariable("PAGE_TYPE","[[${pageType}]]","pageType");
        cfg.view().list().addJsVariable("TAB_STATUS","[[${tabStatus}]]","tabStatus");


        cfg.view().list().addJsVariable("PROJECT_ID","[[${projectId}]]","projectId");
        cfg.view().form().addJsVariable("PROJECT_ID","[[${projectId}]]","projectId");



        cfg.view().form().addJsVariable("CUR_EMP_ID","[[${curEmpId}]]","curEmpId");
        cfg.view().form().addJsVariable("CUR_USER_NAME","[[${curUserName}]]","curUserName");

        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE)
                .setExtendJsFile(WriteMode.IGNORE); //列表HTML页
        //列表HTML页
        //生成代码

//        cfg.overrides().setServiceIntfAnfImpl(WriteMode.IGNORE);
//        cfg.overrides().setControllerAndAgent(WriteMode.IGNORE);
//        cfg.overrides().setPageController(WriteMode.IGNORE);
//        cfg.overrides().setExtendJsFile(WriteMode.IGNORE);

        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        AProjectTaskGtr g=new AProjectTaskGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
//        g.removeByBatchId("471622036347682816");
        //生成菜单
      //  g.generateMenu(ProjectTaskServiceProxy.class, ProjectTaskPageController.class);
    }

}
